package com.zsh.weather.ln.base

import java.lang.ref.WeakReference

open class BasePresenter<V : IView> : IPresenter<V> {
    private var viewReference: WeakReference<V>? = null

    /*
    * 绑定view
    * */
    override fun attachView(v: V) {
        viewReference = WeakReference(v)
    }

    /*
     * 解绑view
     * */
    override fun detachView() {
        if (viewReference != null) {
            viewReference!!.clear()
            viewReference = null
        }
    }
    /*
    * 判断view是否绑定
    * */
    override fun isViewAttached(): Boolean {
        if(viewReference != null) return viewReference!!.get() != null
        return false
    }
    /*
    * 得到view
    * */
    override fun getView(): V? {
        if(viewReference != null) return viewReference!!.get()
        return null
    }
}